package com.pheruagor.handmanager.model.business.activity {
    import flash.errors.IllegalOperationError;


    /**
     * Player Member
     * Represents the activity of a member as a player in the team
     * @see Member, Activity
     */
    public class PlayerActivity extends Activity {
        public static const ACTIVITY_NAME:String = "playerActivity";
        // Positions
        public static const POSITION_RIGHT_WINGMAN:String = "rightWingman";
        public static const POSITION_LEFT_WINGMAN:String = "leftWingman";
        public static const POSITION_RIGHT_BACKCOURT:String = "rightBackcourt";
        public static const POSITION_CENTER_BACKCOURT:String = "centerBackcourt";
        public static const POSITION_LEFT_BACKCOURT:String = "leftBackcourt";
        public static const POSITION_PIVOT:String = "pivot";
        public static const POSITION_GUARDIAN:String = "guardian";

        //-----------------------------------------------------
        // Properties
        //-----------------------------------------------------
        private var m_isLeftWingman:Boolean;
        private var m_isRightWingman:Boolean;
        private var m_isLeftBackcourt:Boolean;
        private var m_isCenterBackcourt:Boolean;
        private var m_isRightBackcourt:Boolean;
        private var m_isPivot:Boolean;
        private var m_isGuardian:Boolean;

        //-----------------------------
        // Constructor
        //-----------------------------
        public function PlayerActivity() {
            super();
        }

        //-----------------------------------------------------
        // Acces
        //-----------------------------------------------------

        public function get isLeftWingman():Boolean {
            return m_isLeftWingman;
        }

        public function set isLeftWingman(value:Boolean):void {
            m_isLeftWingman = value;
        }

        public function get isRightWingman():Boolean {
            return m_isRightWingman;
        }

        public function set isRightWingman(value:Boolean):void {
            m_isRightWingman = value;
        }

        public function get isLeftBackcourt():Boolean {
            return m_isLeftBackcourt;
        }

        public function set isLeftBackcourt(value:Boolean):void {
            m_isLeftBackcourt = value;
        }

        public function get isCenterBackcourt():Boolean {
            return m_isCenterBackcourt;
        }

        public function set isCenterBackcourt(value:Boolean):void {
            m_isCenterBackcourt = value;
        }

        public function get isRightBackcourt():Boolean {
            return m_isRightBackcourt;
        }

        public function set isRightBackcourt(value:Boolean):void {
            m_isRightBackcourt = value;
        }

        public function get isPivot():Boolean {
            return m_isPivot;
        }

        public function set isPivot(value:Boolean):void {
            m_isPivot = value;
        }

        public function get isGuardian():Boolean {
            return m_isGuardian;
        }

        public function set isGuardian(value:Boolean):void {
            m_isGuardian = value;
        }

        //-----------------------------------------------------
        // Operation
        //-----------------------------------------------------
        override public function get name():String {
            return ACTIVITY_NAME;
        }

        override public function clone():Activity {
            var result:PlayerActivity = new PlayerActivity();
            result.id = id;
            result.memberId = memberId;
            result.beginDate = new Date(beginDate);
            result.endDate = new Date(endDate);
            result.description = description;
            result.isLeftWingman = isLeftWingman;
            result.isRightWingman = isRightWingman;
            result.isLeftBackcourt = isLeftBackcourt;
            result.isCenterBackcourt = isCenterBackcourt;
            result.isRightBackcourt = isRightBackcourt;
            result.isPivot = isPivot;
            result.isGuardian = isGuardian;

            return result;
        }

        /**
         * Create a PlayerAvtivity with an object
         * Used for storage/application convertion
         */
        public static function fromObject(item:Object):PlayerActivity {
            if (item == null) {
                throw new ArgumentError("item cannot be null");
            }
            if (!item.hasOwnProperty("id")) {
                throw new ArgumentError("item must contain id property");
            }
            if (!item.hasOwnProperty("memberId")) {
                throw new ArgumentError("item must contain member id property");
            }
            var result:PlayerActivity = new PlayerActivity();
            result.id = item.id;
            result.memberId = item.memberId;
            result.beginDate = new Date(item.beginDate);
            result.endDate = new Date(item.endDate);
            result.description = item.description;
            result.isLeftWingman = Boolean(item.isLeftWingman);
            result.isRightWingman = Boolean(item.isRightWingman);
            result.isLeftBackcourt = Boolean(item.isLeftBackcourt);
            result.isCenterBackcourt = Boolean(item.isCenterBackcourt);
            result.isRightBackcourt = Boolean(item.isRightBackcourt);
            result.isPivot = Boolean(item.isPivot);
            result.isGuardian = Boolean(item.isGuardian);

            return result;
        }

        /**
         * Label build with the concatenation of player positions.
         */
        public function get label():String {
            var result:String = "";
            if (m_isLeftWingman) {
                result = "Ailier gauche";
            }
            if (m_isRightWingman) {
                if (result != "") {
                    result += ", ";
                }
                result += "Ailier droit";
            }
            if (m_isLeftBackcourt) {
                if (result != "") {
                    result += ", ";
                }
                result += "Arrière gauche";
            }
            if (m_isRightBackcourt) {
                if (result != "") {
                    result += ", ";
                }
                result += "Arrière droit";
            }
            if (m_isCenterBackcourt) {
                if (result != "") {
                    result += ", ";
                }
                result += "Demi";
            }
            if (m_isPivot) {
                if (result != "") {
                    result += ", ";
                }
                result += "Pivot";
            }
            if (m_isGuardian) {
                if (result != "") {
                    result += ", ";
                }
                result += "Guardien";
            }
            return result;
        }
    }
}